package com.csx.governance.traffic.mq.rocketmq;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;

/**
 * 可以指明消费的起始位置
 * @author cuisongxu
 * @date 2023/2/28 17:12
 */
public class TrafficRocketMQPushConsumerLifecycleListener implements RocketMQPushConsumerLifecycleListener {

    @Override
    public void prepareStart(DefaultMQPushConsumer consumer) {
        // 指明消费的起始位置
        // TODO 这块需要考量一下如果 基线实例重启了,导致刷新了其消费的位置,那么会不会造成有些消息没有被消费的情况
        consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
        System.out.println("TrafficRocketMQPushConsumerLifecycleListener#prepareStart");
    }
}
